package travlefate.story.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import travlefate.story.R;
import travlefate.story.views.NoScrollGridView;

/**
 * @author keven
 * @data 15/12/21 下午3:07
 * @package travlefate.story.adapter
 */
public class MyStoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private static final int TYPE_HEAD=0,TYPE_ITEM=1,TYPE_FOOT=2;
    private final Context context;

    public MyStoryAdapter(Context context){
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        RecyclerView.ViewHolder holder = null;
        View view;
        switch (viewType){
            case TYPE_HEAD:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_mystory_head, null);
                holder = new HeadHolder(view);
                break;
            case TYPE_ITEM:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_mystory_item, null);
                holder = new ItemHolder(view);
                break;
            case TYPE_FOOT:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_foot, null);
                holder = new FootHolder(view);
                break;
        }

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        switch (getItemViewType(position)){
            case TYPE_ITEM:
//                holder.itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        context.startActivity(new Intent(context, StoryInfoActivity.class));
//                    }
//                });
                break;
            case TYPE_FOOT:
                break;
        }
    }

    @Override
    public int getItemCount() {
        return 10+2;
    }

    @Override
    public int getItemViewType(int position) {
        int type;
        if(position==0){
            type = TYPE_HEAD;
        }else if(position==getItemCount()-1){
            type = TYPE_FOOT;
        }else{
            type= TYPE_ITEM;
        }
        return type;
    }

    /**
     * 列表item
     */
    class ItemHolder extends RecyclerView.ViewHolder{

        View itemView;
        StoryListImgAdapter mImgAdapter ;
        NoScrollGridView mImageGrid;

        public ItemHolder(View itemView) {
            super(itemView);
            this.itemView = itemView;
            mImageGrid = (NoScrollGridView) itemView.findViewById(R.id.story_pics);
            mImgAdapter = new StoryListImgAdapter();
            mImageGrid.setAdapter(mImgAdapter);
        }
    }

    class FootHolder extends RecyclerView.ViewHolder{

        public FootHolder(View itemView) {
            super(itemView);
        }
    }

    class HeadHolder extends RecyclerView.ViewHolder{

        public HeadHolder(View itemView) {
            super(itemView);
        }
    }
}
